﻿
@{
    ViewData["Title"] = "ConfigSettings";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div id="dbConfig">

    <el-tabs v-model="envId" v-on:tab-click="tabEnvClick" type="card" tab-position="left">
        <el-tab-pane :key="item.id"
                     v-for="(item, index) in envList"
                     :label="item.envName"
                     :name="item.id">
            <el-form ref="form" :model="form" label-width="80px">
                <el-row :gutter="24">
                    <el-col :span="24">
                        <el-form-item>
                            <el-button type="primary" v-if="form.configStatus==3" v-on:click="PublishConfig()" size="mini" v-show="pageButtons.includes('finish_projectconfig')">完成</el-button>
                            <el-button type="primary" v-if="form.configStatus==3" v-on:click="PublishConfig()" size="mini" v-show="pageButtons.includes('publish_projectconfig')">发布</el-button>
                            <el-button type="success" v-if="form.configStatus==2" v-on:click="PassConfig()" size="mini" v-show="pageButtons.includes('checkpass_projectconfig')">审核通过</el-button>
                            <el-button type="danger" v-if="form.configStatus==2" v-on:click="UnPassConfig()" size="mini" v-show="pageButtons.includes('checkunpass_projectconfig')">审核不通过</el-button>
                            <el-button type="success" v-if="form.configStatus==1||form.configStatus==4" v-on:click="SaveProject(2)" size="mini" v-show="pageButtons.includes('submitprojectconfig')">提交</el-button>
                            <el-button type="primary" v-if="form.configStatus==1||form.configStatus==4" v-on:click="SaveProject(1)" size="mini" v-show="pageButtons.includes('saveprojectconfig')">保存</el-button>
                            <el-button v-on:click="Back()" size="mini">返回</el-button>

                            <el-button type="info" v-if="form.configStatus==3" v-on:click="ConfigOnline()" style="margin-left:100px;" size="mini" v-show="pageButtons.includes('tongbu_projectconfig')">立刻同步</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="24">
                    <el-col :span="6">
                        <el-form-item label="版本号" required>
                            <el-input v-model="form.versionNumber" disabled></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="20">
                        <el-form-item label="文件路径" required>
                            <el-input v-model="form.path"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                       
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="24">
                        <el-form-item label="配置信息" required>
                            <div class="el-textarea">
                                <textarea placeholder="请输入配置信息" v-model="form.jsonSettings" style="height:800px" class="el-textarea__inner"></textarea>
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </el-tab-pane>
    </el-tabs>

</div>

<script>
    new Vue({
        el: '#dbConfig',
        data() {
            return {
                pageButtons: [],
                envList: [],
                projectId: getQueryString("projectId") || 0,
                envId:'1',
                form: {
                    id:0,
                    path: "",
                    jsonSettings: "",
                    versionNumber: "",
                    configStatus:1,
                    remark:""
                }
            }
        },
        created() {
            this.getEnvList();
            this.GetLastConfigSettings();

            this.$getMenuButtons();
        },
        methods: {
            tabEnvClick: function () {
                this.GetLastConfigSettings();
            },
            GetLastConfigSettings() {
                var _this = this;
                _this.$post("@Url.Action("GetLastConfigSettings", "Project")", {
                    ProjectId: parseInt(_this.projectId),
                    EnvId: parseInt(_this.envId)
                }).then((res) => {
                    if (res.configStatus == 0) res.configStatus = 1;
                    _this.form = res;
                });
            },
            getEnvList() {
                  var _this = this;
                _this.$get("@Url.Action("GetEnvironmentList", "environment")", {}).then((response) => {

                    if (response != null) {
                        response.forEach((item,index) => {
                            item.id = JSON.stringify(item.id)
                        });
                    }
                    _this.envList = response;
                    _this.form.envId = _this.envList[0].id;
                  }).catch((error) => {
                  });
            },
            SaveProject(ConfigStatus) {
                var _this = this;
                var postData = JSON.parse(JSON.stringify(_this.form));
                postData.configStatus = ConfigStatus;
                postData.projectId = parseInt(_this.projectId);
                postData.envId = parseInt(_this.envId);
                _this.$post("@Url.Action("SaveProjectSettings", "Project")", postData).then((res) => {
                    _this.$success(res.message, function () {
                        _this.GetLastConfigSettings();
                    });
                });
            },
            PassConfig: function () {
                var _this = this;
                _this.$post("@Url.Action("SetConfigPass", "Project")", {
                    ProjectId: parseInt(_this.projectId),
                    EnvId: parseInt(_this.envId)
                }).then((res) => {
                    _this.$success(res.message, function () {
                        _this.GetLastConfigSettings();
                    });
                });
            },
            UnPassConfig: function () {
                var _this = this;
                _this.$post("@Url.Action("SetConfigUnPass", "Project")", {
                    ProjectId: parseInt(_this.projectId),
                    EnvId: parseInt(_this.envId)
                }).then((res) => {
                    _this.$success(res.message, function () {
                        _this.GetLastConfigSettings();
                    });
                });
            },
            PublishConfig: function () {
                    var _this = this;
                _this.$post("@Url.Action("PublishConfig", "Project")", {
                    ProjectId: parseInt(_this.projectId),
                    EnvId: parseInt(_this.envId)
                }).then((res) => {
                    _this.$success(res.message, function () {
                        _this.GetLastConfigSettings();
                    });
                });
            },
            Back() {
                this.$back();
            },
        }
    });
</script>